﻿using KouDai.WinPad.Models;
using Newtonsoft.Json.Linq;
using NextEngine.HttpEngine;
using NextEngine.Parser;
using System;
using System.Collections.Generic;

namespace KouDai.WinPad.Parser
{
    public class HoneyParser : NParser
    {
        public override void ParseData(string json, BackData backData)
        {
            List<HoneyEntity> honeyList = (List<HoneyEntity>)backData.ResposeData;
            JArray jarray = JArray.Parse(json);
            JObject jobject = (JObject)jarray[1];
            JToken jtoken = jobject.SelectToken("items");
            foreach (JToken jt in jtoken.Children())
            {
                HoneyEntity honeyEntity = new HoneyEntity();
                honeyEntity.ID = jt["id"].ToString();
                string url = jt["imageUrlForIphone"].ToString();
                honeyEntity.ImageUrlForIphone = url;
                honeyEntity.Url = url;
                honeyEntity.ImgRatio = Convert.ToDouble(jt["imgRatio"].ToString());
                honeyEntity.Name = jt["name"].ToString();
                honeyEntity.Price = jt["price"].ToString();
                //honeyEntity.RequestID = reqID;
                if (jt.ToString().Contains("isPreference"))
                {
                    honeyEntity.IsPreference = Convert.ToBoolean(jt["isPreference"].ToString());
                }
                if (jt.ToString().Contains("timestamp"))
                {
                    honeyEntity.Timestamp = Convert.ToInt64(jt["timestamp"].ToString());
                }
                honeyList.Add(honeyEntity);
            }
        }
    }
}
